package tk.mynoteapp.dev.demo01.concurrenthashmapmisuse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("mytest")
public class MyTestController {

    @RequestMapping("/demo")
    public String demo(HttpServletRequest request, Model model) {
        System.out.println("demo -> jsp");
        List<Map<String, String>> dataList = new ArrayList<>();
        Map<String, String> map1 = new HashMap<>();
        map1.put("type", "png");
        map1.put("filePath", "/111/a.png");

        Map<String, String> map2 = new HashMap<>();
        map2.put("type", "mp4");
        map2.put("filePath", "/111/b.mp4");

        Map<String, String> map3 = new HashMap<>();
        map3.put("type", "mp3");
        map3.put("filePath", "/111/c.mp3");
        dataList.add(map1);
        dataList.add(map2);
        dataList.add(map3);
        model.addAttribute("hello", "world!!!!");
        model.addAttribute("dataList", dataList);
        return "demo";
    }

    @RequestMapping("/login")
    public String login(HttpServletRequest request) {
        request.getSession().setAttribute("test", "demo");
        System.out.println("login -> jsp");
        return "demo2";
    }

    @RequestMapping("/logout")
    public String logout(HttpServletRequest request) {
        request.getSession().removeAttribute("test");
        System.out.println("logout -> jsp");
        return "demo2";
    }
}
